import axios from '@/libs/api.request'
import config from '@/config'

export const getContentTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'ContentService.view',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editContentRecord = async (playload) => {
  let module_name = 'ContentService.add'
  if (playload.id && playload.id !== '') {
    module_name = 'ContentService.update'
  }
  const data = {
    module: module_name,
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getAdminMessageTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'AdminService.messagePage',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const sendMessageRecord = async (playload) => {
  const data = {
    module: 'AdminService.messageSend',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getMessageTemplateTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'AdminService.messageTempView',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editMessageTemplateRecord = async (playload) => {
  // let module_name = 'ContentService.add'
  // if (playload.id && playload.id !== '') {
  //   module_name = 'ContentService.update'
  // }
  const data = {
    module: 'AdminService.messageTempAdd',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}
